import {defineStore} from "pinia";
import http from "../utils/http"
export const useVisit = defineStore("visits",{
    state:()=>{
        return{
            visitList:[],
            total:0
        }
    },
    actions:{
        async getvisitsList(obj){
            let res = await http.get("/api/view",{params:obj});
            if(res.status === 200){
                //处理后端发送过来的数据
                let newarr = res.data.data[0].map(v=>{
                    v.createAt = new Date(v.createAt).toLocaleString()
                    return v
                })
                this.visitList = newarr,
                
                //获取数据的总数
                this.total = res.data.data[1]
                console.log(newarr,"res arr")
                console.log(this.total,"res total")
            }
        },
        //删除搜索记录
        async removevisits(id){
            let res = await http.delete("/api/view/"+id);
            if(res.status === 200){
                this.getvisitsList({page:1,pageSize:12})
            }
        },
        //删除多个
        async removealls (arr){
            arr.map(v=>{
                this.removevisits( this.visitList[v].id)
            })
        }
    },
    getters:{

    }
})